<template>
  <div id="dz_addPeer" class="page in" data-title>
    <div class="container backFFF">
      <header>
        <a @click="$utils.gotopage('','back')" class="pa back"></a>
        <p>修改密码</p>
      </header>

      <div class="addpeer-wrap">
        <div class="flex-wrap-start addPeerModel">
          <span>新密码:</span>
          <input type="password" placeholder="请填写新密码"  v-model="frm.newpwd" />
        </div>

        <div class="flex-wrap-start addPeerModel">
          <span>确认密码:</span>
          <input type="password" placeholder="请填写确认密码"  v-model="frm.confpwd" />
        </div>

         <a href="javascript:void(0)" class="btn uploadBtn" @click="submit" style="margin-top:0.8rem">提交</a>  
      </div>
    </div>
  </div>
</template>


<script>
var mySelf;
export default {
  data() {
    return { 
        frm:{
          newpwd:'',
          confpwd:'',
        }  
 
     };
  },
  beforeCreate() {
			this.$myUtils.isLoginGotoPage();	
		},
  mounted() {
      mySelf = this;
  },
  methods: {

    submit() {
          if (!this.frm.newpwd) {
              return this.$options.methods.showToast('请输入密码');
          }
          if (!this.frm.confpwd) {
              return this.$options.methods.showToast('请输入确认密码');
          }

          if (this.frm.newpwd.length<6 || this.frm.confpwd.length<6 ) { 
              return this.$options.methods.showToast('密码长度必须大等于6位');
          }

          if (this.frm.newpwd!=this.frm.confpwd) {
              return this.$options.methods.showToast('二次输入的密码不相符');
          }
          mySelf.password = mySelf.frm.newpwd;
 
          this.$myUtils.myRequest({
            url: '/user/updatePassword',
            method:'post',
            data:{"user_id":mySelf.$myUtils.getStorage('userId'),'password':mySelf.password}
          }).then(res => {
 
              if (res.statusCode==200) {
                  if (res.data.status==200) {
                    let url = "/pages/personal/me";
                    return  mySelf.$myUtils.successGotoUrl(url);

                  }
              }  else {
                      return uni.showToast({
                        title: res.data.msg || '提交失败！',
                        icon:'none',
                        duration:800
                      });
                  }
                
          })  
          

      },
       showToast(_title) {
          return uni.showToast({
                  title: _title,
                  icon:'none',
                  duration:500
                });
         
      },

     
     

  },
};
</script>


<style lang="scss">
  .upload {
    padding: .3rem;
}

.uploadImg-wrap .addImg {
        width: 77px;
    height: 77px;
    margin-left: 0.3rem;
    margin-top: 0.4rem;
}

.uploadimg{
   position: relative;
}

.uploadimg .delete{

    display: inline-block;
    position: absolute;
    z-index: 999;
    top: 0;
    left: 80%;
    background-color: #f90505;
    width: 17px;
}

</style>

